{% extends 'charts/base.html' %}
{% load dict_extra %}

{% block options %}

{% endblock %}

{% block sidebar %}
{% endblock %}


{% block content %}
    <div class="tabbable">
        <ul class="nav nav-tabs padding-12 tab-color-blue background-blue" id="myTab4">
            <li class="active">
                <a data-toggle="tab" href="#a_1" aria-expanded="false">股票任务-1</a>
            </li>
            <li class="">
                <a data-toggle="tab" href="#a_2" aria-expanded="false">股票任务-2</a>
            </li>
            <li class="">
                <a data-toggle="tab" href="#hk" aria-expanded="false">港股任务</a>
            </li>
            <li class="">
                <a data-toggle="tab" href="#us" aria-expanded="false">美股任务</a>
            </li>
            <li class="">
                <a data-toggle="tab" href="#futures" aria-expanded="true">期货任务</a>
            </li>
            <li class="">
                <a data-toggle="tab" href="#currency" aria-expanded="true">数字货币任务</a>
            </li>
        </ul>

        <div class="tab-content">
            {% for task in task_names %}
                {% with config=task_configs|hash:task.task_name %}
                    <div id="{{ task.task_name }}" class="tab-pane {% if task.task_name == 'a_1' %}active{% endif %}">
                        <form class="form-horizontal task_config_form">
                            <input type="hidden" name="task_name" value="{{ task.task_name }}"/>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right">开启</label>

                                <div class="col-sm-9">
                                    <label>
                                        <input name="is_run" class="ace ace-switch ace-switch-4 btn-rotate"
                                               type="checkbox" value="1"
                                               {% if config.is_run == '1' %}checked {% endif %}/>
                                        <span class="lbl"></span>
                                    </label>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right">间隔分钟数</label>

                                <div class="col-sm-9">
                                    <select class="form-control" name="interval_minutes">
                                        <option value="5" {% if config.interval_minutes == '5' %} selected {% endif %}>
                                            5m
                                        </option>
                                        <option value="15" {% if config.interval_minutes == '15' %}
                                                selected {% endif %}>
                                            15m
                                        </option>
                                        <option value="30" {% if config.interval_minutes == '30' %}
                                                selected {% endif %}>
                                            30m
                                        </option>
                                        <option value="60" {% if config.interval_minutes == '60' %}
                                                selected {% endif %}>
                                            60m
                                        </option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right">自选组</label>

                                <div class="col-sm-9">
                                    <select class="form-control" name="zixuan">
                                        {% for zx in config.zx_list %}
                                            <option value="{{ zx.name }}"
                                                    {% if config.zixuan == zx.name %}selected{% endif %}>{{ zx.name }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                            </div>


                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right">检查周期</label>

                                <div class="col-sm-9">
                                    <input type="text" name="frequencys" value="{{ config.frequencys }}"
                                           class="col-xs-10 col-sm-5"/>
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">英文逗号分割，例如：30m,5m</span>
											</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right">检查笔背驰</label>

                                <div class="col-sm-9">
                                    <input type="text" name="check_beichi" value="{{ config.check_beichi }}"
                                           class="col-xs-10 col-sm-5"/>
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">bi 笔背驰，pz 盘整背驰， ps 趋势背驰；英文逗号分割，例如：bi,pz,qs</span>
											</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right">检查笔买卖点</label>

                                <div class="col-sm-9">
                                    <input type="text" name="check_mmd" value="{{ config.check_mmd }}"
                                           class="col-xs-10 col-sm-5"/>
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">1buy 一买 1sell 一卖 等设置；英文逗号分割，例如：1buy,2buy,l2buy,1sell,3sell</span>
											</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right">检查线段背驰</label>

                                <div class="col-sm-9">
                                    <input type="text" name="check_beichi_xd" value="{{ config.check_beichi_xd }}"
                                           class="col-xs-10 col-sm-5"/>
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">xd 线段背驰，pz 盘整背驰， ps 趋势背驰；英文逗号分割，例如：xd,pz,qs</span>
											</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right">检查线段买卖点</label>

                                <div class="col-sm-9">
                                    <input type="text" name="check_mmd_xd" value="{{ config.check_mmd_xd }}"
                                           class="col-xs-10 col-sm-5"/>
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">1buy 一买 1sell 一卖 等设置；英文逗号分割，例如：1buy,2buy,l2buy,1sell,3sell</span>
											</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right">检查线段背驰</label>

                                <div class="col-sm-9">
                                    <input type="text" name="check_beichi_xd" value="{{ config.check_beichi_xd }}"
                                           class="col-xs-10 col-sm-5"/>
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">xd 线段背驰，pz 盘整背驰， ps 趋势背驰；英文逗号分割，例如：xd,pz,qs</span>
											</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right">检查线段买卖点</label>

                                <div class="col-sm-9">
                                    <input type="text" name="check_mmd_xd" value="{{ config.check_mmd_xd }}"
                                           class="col-xs-10 col-sm-5"/>
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">1buy 一买 1sell 一卖 等设置；英文逗号分割，例如：1buy,2buy,l2buy,1sell,3sell</span>
											</span>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right">发送消息</label>

                                <div class="col-sm-9">
                                    <label>
                                        <input name="is_send_msg" class="ace ace-switch ace-switch-5" type="checkbox"
                                               value="1" {% if config.is_send_msg == '1' %} checked {% endif %}>
                                        <span class="lbl"></span>
                                    </label>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right">缠论配置（分型）</label>

                                <div class="col-sm-9 red">
                                    根据在 WEB 页面中已经设置的缠论配置项进行计算
                                </div>
                            </div>

                            <div class="clearfix form-actions">
                                <div class="col-md-offset-3 col-md-9">
                                    <button class="btn btn-info" type="submit">
                                        <i class="ace-icon fa fa-check bigger-110"></i>
                                        保存
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                {% endwith %}
            {% endfor %}
        </div>
    </div>

{% endblock %}

{% block js %}
    <script>
        $(
            function () {
                $('.task_config_form').submit(function () {
                    var task_config = $(this).serialize();
                    $.ajax({
                        type: "POST",
                        url: "/tasks/save",
                        data: task_config,
                        dataType: 'json',
                        success: function (result) {
                            if (result['code'] === 200) {
                                alert('保存成功');
                            } else {
                                alert('保存失败')
                            }
                        }
                    });
                    return false
                });

            }
        );
    </script>
{% endblock %}